﻿using System.Windows;
using System.Windows.Media;
using Ricciolo.PaperBoy.Feeds;
using Project_CFT2.Behavior;
using Project_CFT2.ViewModel;
using Project_CFT2.View;
using Project_CFT2.Factory;
using Project_CFT2.RFID;
using TableCamCommunicator;
using GroupLab.Networking;
using Multitouch.Framework.WPF.Input;
using Multitouch.Framework.WPF;
using System.Windows.Controls;


namespace Project_CFT2
{
    
    public partial class GlowWindow
    {

        public GlowWindow()
        {
            
            MultitouchScreen.AddContactEnterHandler(this, ElementEnterHandler);
            MultitouchScreen.AddContactRemovedHandler(this, ElementRemoveHandler);
            
            InitializeComponent();
            
            
        }
        private static void ElementEnterHandler(object sender, ContactEventArgs e)
        {
            
            var element = sender as IInputElement;

            var winElement = sender as GlowWindow;

            
            
            if (element != null)
            {

                Glow newView;
                Point position = e.GetPosition(winElement);
                newView = new Glow();
                newView.SetValue(Canvas.LeftProperty, position.X-136/2);
                newView.SetValue(Canvas.TopProperty, position.Y-138/2);
                MultitouchScreen.AddContactEnterHandler(newView, ElementEnterHandler2);
                winElement.glowPanel.Children.Add(newView);
            }

        }
        private static void ElementRemoveHandler(object sender, ContactEventArgs e)
        {
            var element = sender as GlowWindow;

            element.glowPanel.Children.Remove(e.Contact.DirectlyOver as UIElement);
        }


        private static void ElementEnterHandler2(object sender, ContactEventArgs e)
        {
            var element = sender as IInputElement;
            if (element != null)
            {
                e.Contact.Capture(element);
            }
        }
     
        public void AddItem(Point position)
        {
            FrameworkElement newView;

            newView = new Glow();


            newView.SetValue(Canvas.LeftProperty, position.X);
            newView.SetValue(Canvas.RightProperty, position.Y);

            
            glowPanel.Children.Add(newView);
        }
  

    }
}
